#include"../../client/rpc_client.hpp"
#include"../../common/detail.hpp"

void callback(const Json::Value &result) {
    ILOG("callback result: %d", result.asInt());
}

int main()
{
    RPC_project::client::RpcClient client(false ,"127.0.0.1" ,9090);

    Json::Value params , result;
    params["num1"]=11;
    params["num2"]=666;
    bool ret = client.call("Add" ,params,result);//同步发送
    if(ret != false)
    {
        ILOG("result: %d" ,result.asInt() );
    }

    // 异步发送
    std::future<Json::Value> res_future;
    params["num1"] =22;
    params["num2"] =66;
    bool ret1 = client.call("Add", params, res_future); 
    if (ret1 != false)
    {
        result = res_future.get(); // 可能抛出异常
        ILOG("result: %d" ,result.asInt() );
        // 处理结果
    }



    // 异步调用（回调方式）
    Json::Value params2;
    params2["num1"] = 55;
    params2["num2"] = 99;
    if (!client.call("Add", params2, callback)) {  // 假设回调方式的call返回成功为true
        std::cerr << "Async call (callback) failed" << std::endl;
    }
    DLOG("---------------------------------\n");

    std::this_thread::sleep_for(std::chrono::seconds(1));

    return 0;
}
